package com.fashion.thread;

import com.fashion.model.News;
import com.fashion.service.NewsService;
import com.fashion.utils.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: gnyk
 * Date: 13-5-4
 */
public class RefreshNewsHtmlThread extends  Thread {
    private static final Logger logger = Logger.getLogger(RefreshNewsHtmlThread.class);
    private String folder;
    private NewsService newsService;
    private List<News> newsList;
    private String urlPrefix;

    public RefreshNewsHtmlThread(String folder, NewsService newsService, List<News> newsList, String urlPrefix) {
        this.folder = folder;
        this.newsService = newsService;
        this.newsList = newsList;
        this.urlPrefix = urlPrefix;
    }

    @Override
    public void run() {
        for (News news : newsList) {
            String url = urlPrefix + "/n-"+ news.getId()+".html";
            try {
                newsService.saveHtmlNews(url, urlPrefix,folder );
            } catch (Exception e) {
                logger.error("failed to save news html: " + url + " reason: " + e.getMessage());
            }
        }
    }
}
